package org.wso2.carbon.registry.custom.skb.services;

import org.wso2.carbon.registry.common.services.RegistryAbstractAdmin;
import org.wso2.carbon.registry.custom.skb.beans.SKBBean;
import org.wso2.carbon.registry.custom.skb.util.SKBUtil;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.core.Resource;

public class SKBService extends RegistryAbstractAdmin{

    public SKBBean getSKBBean(String path) throws Exception {
        return SKBUtil.getSKBBean(path);
    }

    public void addColletion(String sPath) throws Exception{
        Registry registry = getRootRegistry();
        Collection collection = registry.newCollection();
        registry.put(sPath, collection);

    }

    public void addResource(String sPath, String content) throws Exception{
        Registry registry = getRootRegistry();
        Resource r1 = registry.newResource();
        r1.setMediaType("text/plain");
        r1.setContent(content.getBytes());
        registry.put(sPath, r1);

    }

    public void addProblemResource(String sPath, String content) throws Exception{
        Registry registry = getRootRegistry();
        Resource r1 = registry.newResource();
        r1.setMediaType("skb");

        r1.setContent(content.getBytes());
        registry.put(sPath, r1);

    }

    public void addAssociation(String sPath, String dPath, String type) throws Exception{
        Registry registry = getRootRegistry();
        registry.addAssociation(sPath, dPath, type);
        
    }

    public void applyTag(String sPath, String tag) throws Exception{
        Registry registry = getRootRegistry();
        registry.applyTag(sPath, tag);
    }
}
